package com.mobiletrain.org.motherkitch.fenlei.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lidroid.xutils.BitmapUtils;
import com.mobiletrain.org.motherkitch.R;
import com.mobiletrain.org.motherkitch.fenlei.bean.Cook;
import com.mobiletrain.org.motherkitch.utils.ImageLoad;

import java.util.ArrayList;

/**
 * Created by aaa on 15-4-27.
 */
public class ThirdList2Adapter extends BaseAdapter {
    private final BitmapUtils bitmaputil;
    private ArrayList<Cook>arrays;
    Context context;

    public ThirdList2Adapter(ArrayList<Cook> arrays, Context context) {
        this.arrays = arrays;
        this.context = context;
        bitmaputil=ImageLoad.getBitmapUtils(context);
    }

    @Override
    public int getCount() {
        if(arrays!=null){
            return arrays.size();
        }
        return 0;
    }

    @Override
    public Object getItem(int position) {
        return arrays.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        MyHoder3 hoder3=null;
        if(convertView==null){
            convertView= LayoutInflater.from(context).inflate(R.layout.fenlei_third_list2_item,null);
            hoder3=new MyHoder3();
            hoder3.tou= (ImageView) convertView.findViewById(R.id.third_list2_tou);
            hoder3.icon= (ImageView) convertView.findViewById(R.id.third_list2_icon);
            hoder3.name= (TextView) convertView.findViewById(R.id.third_list2_name);
            hoder3.time= (TextView) convertView.findViewById(R.id.third_list2_time);
            hoder3.content= (TextView) convertView.findViewById(R.id.third_list2_content);
            convertView.setTag(hoder3);
        }else{
            hoder3= (MyHoder3) convertView.getTag();
        }
        Cook cook=arrays.get(position);
        bitmaputil.display(hoder3.icon,cook.getPic());
        bitmaputil.display(hoder3.tou,cook.getAvatar());
        hoder3.name.setText(cook.getNickname());
        hoder3.time.setText(cook.getAge_str());
        hoder3.content.setText(cook.getContent());
        return convertView;
    }
    class MyHoder3{
        ImageView tou;
        ImageView icon;
        TextView name;
        TextView time;
        TextView content;
    }
}
